<?php
// No direct access to this file
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

class ManagerViewPond extends JView {
	
	var $table = null;
	
    function __construct() {
        ManagerHelper::showMenuPim("pond");
        $this->table =& JTable::getInstance('Pond', 'Table');	  
        parent::__construct();
    }	
    
	function display() {
		$mainframe = JFactory::getApplication();
        $this->setLayout('display');
        
        $where = $this->filter($mainframe);
        
        ManagerHelper::showToolBar('Pond Management', true, true);
        						
        $limit				= $mainframe->getUserStateFromRequest( 'ponds.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
        $limitstart 		= $mainframe->getUserStateFromRequest( 'ponds.limitstart', 'limitstart', 0, 'int' );
        $filter_order		= $mainframe->getUserStateFromRequest( 'ponds.filter_order', 'filter_order', 'id', 'cmd' );
        $filter_order_Dir	= $mainframe->getUserStateFromRequest( 'ponds.filter_order_Dir', 'filter_order_Dir', ManagerHelper::ORDER_DIR, 'word' );

        $Model = JModel::getInstance('Pond', 'PimModel');
        $Model->getData($total, $dbrow, $filter_order, $filter_order_Dir, $limitstart, $limit, $where);
		
        jimport('joomla.html.pagination');
        $pageNav = new JPagination( $total, $limitstart, $limit );
       
        $this->assign('TOTAL_ROW', $total);
        $this->assign('dbrow', $dbrow);
        $this->assign('LIST_FOOTER_PAV', $pageNav->getListFooter());
        $this->assign('FORM_ORDER', $filter_order);
        $this->assign('FORM_ORDER_DIR',$filter_order_Dir);

        parent::display();
    }
    
 	function addForm() {		
		$mainframe = JFactory::getApplication();
		$this->setLayout('form');					
		$cid = JRequest::getVar('cid');
	    
        if(!empty($cid)) {
			$rows = $this->table;
			$rows->load($cid[0]);	
			$this->assign('rows', $rows);
		}
		
		$Customer = JModel::getInstance('Customer', 'PimModel');
		$arr_Customer = array();
		$arr_Customer = $Customer->getListSelectBox();
		
		$lists['customer_code'] = JHTML::_('select.genericlist',$arr_Customer,"user_id","  ",'id','name',intval($rows->customer_code));
		$this->assign('lists',$lists);
		
		parent::display();
    }
    
	function filter($mainframe) {
    	$where = array();
 		$filter_name = $mainframe->getUserStateFromRequest('filter.fishes.name', 'filter_name', '', 'cmd');
 		
    	if ($filter_name) {
 			$where[] = 'p.name LIKE "%' . $filter_name . '%"';
 		}
 		
 		$mainframe->setUserState('filter_ponds', $where);
 		
 		$this->assign('filter_name', $filter_name); 		
 		
 		return $where;
    }
}
